﻿using System.Data;
using System.Data.SqlClient;
using Pantry.DataAccess;
using NUnit.Framework;
using Pantry.Entity;

namespace Pantry.UnitTest
{
    [TestFixture]
    public class TestTrustDistrictDao
    {
        private SqlConnection sqlConnection;
        private TrustDistrictDao trustDistrictDao;
        private TrustDistrict trustDistrict;

        [SetUp]
        public void Initialize1()
        {
            const string connectionString = @"Server=10.16.102.126;Database=Pantry_MockProject;Integrated Security=True;";
            sqlConnection = new SqlConnection(connectionString);
            trustDistrictDao = new TrustDistrictDao(sqlConnection);
            trustDistrict = new TrustDistrict
                                {
                                    TrustDistrictId = 1,
                                    TrustDistrictName = "Trust District Name",
                                    Description = "Description",
                                    TrustRegionId = 1,
                                    IsActive = true
                                };
        }

        [Test]
        public void TestRetrieveTrustDistictsByRegion()
        {
            var actual = trustDistrictDao.RetrieveData("TrustRegionId","1",SqlDbType.Int);
            var result = actual.Rows.Count > 0;
            Assert.AreEqual(true,result);
        }

        [Test]
        public void TestRetrieveTrustDistrict()
        {
            var actual = (TrustDistrict)trustDistrictDao.RetrieveEntity(1);
            Assert.AreEqual(1,actual.TrustDistrictId);
        }

        [Test]
        public void TestInsertTrustDistrict()
        {
            var actual = trustDistrictDao.Insert(trustDistrict);
            Assert.AreEqual(-2,actual);
        }

        [Test]
        public void TestUpdateTrustDistrict()
        {
            trustDistrict.TrustDistrictName = "New trust district";
            var actual = trustDistrictDao.Update(trustDistrict);
            Assert.AreEqual(1,actual);
        }

        [Test]
        public void TestChangeIsActiveTrustDistrict()
        {
            var actual = trustDistrictDao.ChangeIsActive("TrustDistrict","DistrictName","True","TrustDistrictId",1);
            Assert.AreEqual(1,actual);
        }
    }
}
